<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    let arr = [1, 2, 2, 4, null, null, '3', 'abc', 3, 5, 4, 1, 2, 2, 4, null, null, '3', 'abc', 3, 5, 4];
    //---第一种利用对象的key唯一---
    function one(arr) {
      let obj = {};
      for (let i = 0; i < arr.length; i++) {
        let item = arr[i]
        if (obj[item] !== undefined) {
          arr.splice(i, 1)
          i--;
          continue;

        }
        obj[item] = item
      }
    }

    //---第二种交换元素位置从而换调 splice方法---
    function two(arr) {
      let obj = {};
      for (let i = 0; i < arr.length; i++) {
        let item = arr[i]
        if (obj[item] !== undefined) {
          arr[i] = arr[arr.length - 1]
          arr.length--;
          i--;
          continue;
        }
        obj[item] = item
      }
    }
   
    //---第三种高阶函数---
    function three(arr) {
      return arr.filter((item,index) => arr.indexOf(item) === index)
    }


    // one(arr)
    // two(arr)
    console.log(three(arr)); 
    // console.log(arr);
  </script>
</body>

</html>